import java.util.Arrays;

public class MyList {
    private int size=0;
    private int capacity=10;
    private int[] array;
    private void checkgrow(){
        if(size==0){
            array=new int[capacity];
        }
        if(size==capacity){
            capacity=capacity+capacity>>1;
            int[] newarray=new int[capacity];
            System.arraycopy(array,0,newarray,0,size);
            array=newarray;
        }
    }
    public void addLast(int element){
        checkgrow();
        array[size]=element;
        this.size++;
    }
    public void add(int indx,int element){
        checkgrow();
        System.arraycopy(array,indx,array,indx+1,size-indx);
        array[indx]=element;
        size++;
    }
    public int remove(int indx){
        int remove=array[indx];
        System.arraycopy(array,indx+1,array,indx,size-indx-1);
        size--;
        return remove;
    }
    public int get(int indx){
        return array[indx];
    }
    public boolean contain(int x){
        for (int i = 0; i < size; i++) {
            if(array[i]==x){
                return true;
            }
        }
        return false;
    }
    public void foreach(){
        for (int i = 0; i < size; i++) {
            System.out.println(array[i]);
        }
    }
}
